package com.hxs.hxsserver.controller.relay;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hxs.hxsserver.controller.BaseController;
import com.hxs.hxsserver.domain.dto.IdDTO;
import com.hxs.hxsserver.domain.dto.JsonResult;
import com.hxs.hxsserver.domain.dto.device.DeviceStatusQueryDTO;
import com.hxs.hxsserver.domain.dto.device.QueryRelayListDTO;
import com.hxs.hxsserver.domain.dto.device.RelayDTO;
import com.hxs.hxsserver.domain.dto.device.RelayManageDTO;
import com.hxs.hxsserver.domain.entity.device.DeviceStatusHistory;
import com.hxs.hxsserver.service.RelayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author liuchuan
 * @create 2024/9/29
 */
@Slf4j
@RestController
@Api(value = "继电器管理")
@RequestMapping("relay")
public class RelayController  extends BaseController {

    @Resource
    RelayService relayService;

    @GetMapping("/getRelayList")
    @ApiOperation(value = "获取继电器列表列表")
    public JsonResult<IPage<RelayDTO>> getRelayList(@Validated QueryRelayListDTO queryRelayListDTO){
        return JsonResult.success(relayService.getRelayList(queryRelayListDTO));
    }

    @PostMapping("/updateRelay")
    @ApiOperation(value = "编辑继电器")
    public JsonResult<Boolean> updateRelay(@RequestBody @Validated RelayDTO relayDTO){
        return JsonResult.success(relayService.updateRelay(relayDTO));
    }

    @PostMapping("/deleteRelay")
    @ApiOperation(value = "删除继电器")
    public JsonResult<Boolean> deleteRelay(@RequestBody @Validated IdDTO idDTO){
        return JsonResult.success(relayService.deleteRelay(idDTO));
    }

    @GetMapping("/getRelayById")
    @ApiOperation(value = "查看继电器信息")
    public JsonResult<RelayDTO> getRelayById(@Validated IdDTO idDTO){
        return JsonResult.success(relayService.getRelayById(idDTO));
    }

    @PostMapping("/insertRelay")
    @ApiOperation(value = "新增继电器")
    public JsonResult<Boolean> insertRelay(@RequestBody @Validated RelayDTO relayDTO){
        return JsonResult.success(relayService.insertRelay(relayDTO));
    }

    @PostMapping("/relayStatusManage")
    @ApiOperation(value = "继电器开关控制")
    public JsonResult<Boolean> relayStatusManage(@RequestBody @Validated RelayManageDTO relayManageDTO){
        return JsonResult.success(relayService.relayStatusManage(relayManageDTO,getUserId()));
    }
    @GetMapping("/getRelayLog")
    @ApiOperation(value = "获取继电器操作记录")
    public JsonResult<IPage<DeviceStatusHistory>> getRelayLog(@ApiParam(value = "查询参数") @Validated DeviceStatusQueryDTO deviceListQueryDTO){
        return JsonResult.success(relayService.getRelayLog(deviceListQueryDTO));
    }
}
